package com.jsmtr.rms.controller.writtentest;

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock;
import com.jsmtr.rms.entity.LimitRequest;
import com.jsmtr.rms.entity.PlanManage;
import com.jsmtr.rms.entity.ResponseBuilder;
import com.jsmtr.rms.service.IPlanManageService;
import org.apache.xpath.operations.Bool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.Map;

/**
 * @author wyh
 */
@Controller
@RequestMapping("/PlanManage")
public class PlanManageController {
    @Autowired
    IPlanManageService planService;

    @RequestMapping("/getExamList")
    public void getExamList(LimitRequest limitRequest, HttpServletResponse response) {
        try {
            int curPage = limitRequest.getPage();
            int pageSize = limitRequest.getLimit();
            String accountName = null;
            String examRoom = null;
            String invigilator = null;
            String keyWord = null;
            Map<String, Object> search = limitRequest.getSearch();
            if (search != null) {
                accountName = (String) search.get("accountName");
                examRoom = (String) search.get("examRoom");
                invigilator = (String) search.get("invigilator");
                keyWord = (String) search.get("keyWord");
            }
            String result = planService.getExamList(curPage, pageSize, accountName, examRoom, invigilator, keyWord, response);

            ResponseBuilder responseBuilder = new ResponseBuilder();
            PrintWriter writer = response.getWriter();
            writer.write(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/addExam")
    public void addExam(@RequestBody PlanManage planManage) {
        planService.addExam(planManage);
    }

    @RequestMapping("/editExamTime")
    public void editExamTime(@RequestBody PlanManage planManage) {
        planService.editExamTime(planManage);
    }

    @RequestMapping("/addMissionTicket")
    public void admissionTicket(PlanManage planManage) {
//        planService.admissionTicket(planManage);
    }

    @RequestMapping("/examSign")
    public void examSign(PlanManage planManage) {
        planService.examSign(planManage);
    }

    @RequestMapping("/getAchievementList")
    public void getAchievementList(LimitRequest limitRequest, HttpServletResponse response) {
        try {
            PrintWriter writer = response.getWriter();
            String result = planService.getAchievementList(limitRequest.getPage(), limitRequest.getLimit(), limitRequest.getSearch());
            writer.write(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/importAchievement")
    public void importAchievement(HttpServletResponse response) {

    }
}
